﻿using System;
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage;
using Coevery.Fields.ViewModels;


namespace Coevery.Fields.Fields {
    public class MapField : ContentField {
      
          public GeographicalPoint Value {
            get {
                var temp = Storage.Get<string>(Name);
                if (temp != String.Empty)
                {
                    string[] coords = temp.Split(new string[] { "#" }, StringSplitOptions.None);
                    return new GeographicalPoint(float.Parse(coords[0]), float.Parse(coords[1]));
                }else{
                    return null;
                }
                
            }
            set {
                if (value != null) {
                    Storage.Set(((GeographicalPoint)value).Latitude+"#"+((GeographicalPoint)value).Longitude);
                }
                 
            }
         }

        /*
        public GeographicalPoint Value
        {
            get { return new GeographicalPoint(41.617F, 2.3F); }
            set {}

            // POR LO PRONTO NO PERSISTO
            //get { return Storage.Get<GeographicalPoint>(Name); }
            //set { Storage.Set(value); }
            
        }
        */
    }
}
